package api;

import com.alibaba.fastjson.JSON;
import exception.ActiveUserException;
import service.UserService;
import utils.Response;
import utils.ResponseCode;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ActiveUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String activeCode=req.getParameter("activeCode");
        UserService userService=new UserService();
        Response build=null;
        try {
            userService.active(activeCode);
            build=Response.build(ResponseCode.SUCCESS_ACTIVE);
        }catch (ActiveUserException e){
            e.printStackTrace();
            build=Response.build(e.getResponseCode());
        }
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(JSON.toJSON(build).toString());

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
